package org.gap.web.jsf;

import java.util.List;

import org.gap.dao.PatientDAO;
import org.gap.dao.RendezVousDAO;
import org.gap.dao.TiersDAO;

import org.gap.domain.Patient;
import org.gap.domain.RendezVous;
import org.gap.domain.Tiers;

import org.gap.service.PatientService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Component;

import org.springframework.transaction.annotation.Transactional;

/**
 * Spring Component that handles CRUD requests for Patient entities
 * 
 */
@Scope("session")
@Component("PatientComponent")
public class PatientComponentImpl implements PatientComponent {

	/**
	 * Data type variable that provides CRUD operations for Patient entities
	 * 
	 */
	private Patient patient;

	/**
	 * DAO injected by Spring that manages Tiers entities
	 * 
	 */
	private Tiers tiers;

	/**
	 * DAO injected by Spring that manages RendezVous entities
	 * 
	 */
	private RendezVous rendezvouses;

	/**
	 * DAO injected by Spring that manages Patient entities
	 * 
	 */
	@Autowired
	private PatientDAO patientDAO;

	/**
	 * DAO injected by Spring that manages RendezVous entities
	 * 
	 */
	@Autowired
	private RendezVousDAO rendezVousDAO;

	/**
	 * DAO injected by Spring that manages Tiers entities
	 * 
	 */
	@Autowired
	private TiersDAO tiersDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Patient entities
	 * 
	 */
	@Autowired
	private PatientService patientService;

	/** 
	 */
	public PatientComponentImpl() {
	}

	/**
	 * View an existing RendezVous entity
	 * 
	 */
	@Transactional
	public String selectPatientRendezVouses(Integer patient_patPatient, Integer related_rendezvouses_rdvRendezVous) {
		rendezvouses = rendezVousDAO.findRendezVousByPrimaryKey(related_rendezvouses_rdvRendezVous, -1, -1);
		return "/jsf/patient/rendezvouses/viewRendezVouses.xhtml";
	}

	/**
	 * Save an existing RendezVous entity
	 * 
	 */
	@Transactional
	public String savePatientRendezVouses(Integer patient_patPatient, RendezVous rendezvous) {
		patient = patientService.savePatientRendezVouses(patient_patPatient, rendezvous);

		return "/jsf/patient/viewPatient.xhtml";
	}

	/**
	 * Create a new RendezVous entity
	 * 
	 */
	@Transactional
	public String newPatientRendezVouses(Integer patient_patPatient) {
		rendezvouses = new RendezVous();

		return "/jsf/patient/rendezvouses/createRendezVouses.xhtml";
	}

	/**
	 * Select the child RendezVous entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeletePatientRendezVouses(Integer patient_patPatient, Integer related_rendezvouses_rdvRendezVous) {
		rendezvouses = rendezVousDAO.findRendezVousByPrimaryKey(related_rendezvouses_rdvRendezVous);

		return "/jsf/patient/rendezvouses/deleteRendezVouses.xhtml";
	}

	/**
	 * Create a new Patient entity
	 * 
	 */
	@Transactional
	public String newPatient() {
		patient = new Patient();

		return "/jsf/patient/createPatient.xhtml";
	}

	/**
	 * Create a new Tiers entity
	 * 
	 */
	@Transactional
	public String newPatientTiers(Integer patient_patPatient) {
		tiers = new Tiers();

		return "/jsf/patient/tiers/createTiers.xhtml";
	}

	/**
	 * Get Tiers entity by Patient
	 * 
	 */
	@Transactional
	public Tiers getPatientTiers(Integer patPatientKey) {
		return patientDAO.findPatientByPrimaryKey(patPatientKey).getTiers();
	}

	/**
	 * Getter for variable Patient
	 * 
	 */
	@Transactional
	public Patient getPatient() {
		return patient;
	}

	/**
	 * Delete an existing Patient entity
	 * 
	 */
	@Transactional
	public String deletePatient(Integer patPatientKey) {
		Patient patient = patientDAO.findPatientByPrimaryKey(patPatientKey);
		patientService.deletePatient(patient);
		return "/jsf/patient/listPatients.xhtml";
	}

	/**
	 * Getter for variable Patient
	 * 
	 */
	@Transactional
	public Tiers getTiers() {
		return tiers;
	}

	/**
	 * Delete an existing RendezVous entity
	 * 
	 */
	@Transactional
	public String deletePatientRendezVouses(Integer patient_patPatient, Integer related_rendezvouses_rdvRendezVous) {
		patient = patientService.deletePatientRendezVouses(patient_patPatient, related_rendezvouses_rdvRendezVous);

		return "/jsf/patient/viewPatient.xhtml";
	}

	/**
	 * Save an existing Tiers entity
	 * 
	 */
	@Transactional
	public String savePatientTiers(Integer patient_patPatient, Tiers tiers) {
		patient = patientService.savePatientTiers(patient_patPatient, tiers);

		return "/jsf/patient/viewPatient.xhtml";
	}

	/**
	 * Show all RendezVous entities by Patient
	 * 
	 */
	@Transactional
	public List<RendezVous> listPatientRendezVouses(Integer patPatientKey) {
		return new java.util.ArrayList<RendezVous>(patientDAO.findPatientByPrimaryKey(patPatientKey).getRendezVouses());
	}

	/**
	 * Delete an existing Tiers entity
	 * 
	 */
	@Transactional
	public String deletePatientTiers(Integer patient_patPatient, Integer related_tiers_tieTiers) {
		patient = patientService.deletePatientTiers(patient_patPatient, related_tiers_tieTiers);

		return "/jsf/patient/viewPatient.xhtml";
	}

	/**
	 * Select the Patient entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeletePatient(Integer patPatientKey) {
		patient = patientDAO.findPatientByPrimaryKey(patPatientKey);

		return "/jsf/patient/deletePatient.xhtml";
	}

	/**
	 * Select an existing Patient entity
	 * 
	 */
	@Transactional
	public String selectPatient(Integer patPatientKey) {
		patient = patientDAO.findPatientByPrimaryKey(patPatientKey);

		return "/jsf/patient/viewPatient.xhtml";
	}

	/**
	 * View an existing Tiers entity
	 * 
	 */
	@Transactional
	public String selectPatientTiers(Integer patient_patPatient, Integer related_tiers_tieTiers) {
		tiers = tiersDAO.findTiersByPrimaryKey(related_tiers_tieTiers, -1, -1);
		return "/jsf/patient/tiers/viewTiers.xhtml";
	}

	/**
	 * Edit an existing RendezVous entity
	 * 
	 */
	@Transactional
	public String editPatientRendezVouses(Integer patient_patPatient, Integer related_rendezvouses_rdvRendezVous) {
		rendezvouses = rendezVousDAO.findRendezVousByPrimaryKey(related_rendezvouses_rdvRendezVous, -1, -1);
		return "/jsf/patient/rendezvouses/editRendezVouses.xhtml";
	}

	/**
	 * Edit an existing Patient entity
	 * 
	 */
	@Transactional
	public String editPatient(Integer patPatientKey) {
		patient = patientDAO.findPatientByPrimaryKey(patPatientKey);

		return "/jsf/patient/editPatient.xhtml";
	}

	/**
	 * Show all Patient entities
	 * 
	 */
	@Transactional
	public List<Patient> listPatients() {
		return new java.util.ArrayList<Patient>(patientService.loadPatients());
	}

	/**
	 * Save an existing Patient entity
	 * 
	 */
	@Transactional
	public String savePatient(Patient patient) {
		patientService.savePatient(patient);
		return "/jsf/patient/listPatients.xhtml";
	}

	/**
	 * Select the child Tiers entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeletePatientTiers(Integer patient_patPatient, Integer related_tiers_tieTiers) {
		tiers = tiersDAO.findTiersByPrimaryKey(related_tiers_tieTiers);

		return "/jsf/patient/tiers/deleteTiers.xhtml";
	}

	/**
	 * Getter for variable Patient
	 * 
	 */
	@Transactional
	public RendezVous getRendezvouses() {
		return rendezvouses;
	}

	/**
	 * Edit an existing Tiers entity
	 * 
	 */
	@Transactional
	public String editPatientTiers(Integer patient_patPatient, Integer related_tiers_tieTiers) {
		tiers = tiersDAO.findTiersByPrimaryKey(related_tiers_tieTiers, -1, -1);
		return "/jsf/patient/tiers/editTiers.xhtml";
	}

}
